﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using System.Web;
using Antu.WorkFlowFactory;
using System.Data;

namespace WebSys.UI.OfficeFlow
{
    public class FileListSkin : MPBasicTemplate
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        CustomGridView CustomGridView1;
        protected string UserId
        {
            get { if (base.Page.Session["UserId"] != null) { return base.Page.Session["UserId"].ToString(); } else { return string.Empty; } }
            set { base.Page.Session["UserId"] = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            InitControl();
            if (!Page.IsPostBack)
            {
                BindData();
            }
            CustomGridView1.OnLoadData += new EventHandler(CustomGridView1_OnLoadData);
            CustomGridView1.RowDeleting += new GridViewDeleteEventHandler(CustomGridView1_RowDeleting);
        }
        protected void InitControl()
        {
            CustomGridView1 = (CustomGridView)FindControl("CustomGridView1"); 
        }
        protected void BindData()
        {
            CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            string strIId = string.Empty;
            if (!string.IsNullOrEmpty(HttpContext.Current.Request.Params["IID"]))
            {
                strIId = HttpContext.Current.Request.Params["IID"];
            }
            DataTable files = _FlowFactoryProvider.GetAllFile(strIId);
            CustomGridView1.DataSource = files;
            CustomGridView1.PageSize = 10;
            CustomGridView1.RecordCount = files.Rows.Count;
            CustomGridView1.DataKeyNames = new string[] { "AID" };
            CustomGridView1.DataBind();
        }
        protected void CustomGridView1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }
        protected void CustomGridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string fjid = CustomGridView1.DataKeys[e.RowIndex].Value.ToString();
            bool del = _FlowFactoryProvider.DelFileByID(fjid);
            if (del)
            {
                BindData();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除成功！');window.parent.inittree();", true);
            }
        }


    }
}


